<h1>Set highlighted posts and assign images</h1>
<?PHP
	$templatePath= get_absolute_template_path(); 
	
	$settings=array();
	$settings=	 json_decode(file_get_contents($templatePath."/settings.txt"));
?>
Image location base:<strong><?PHP bloginfo("template_url");?>/data.pics/content-slider/</strong>
<br/><br/>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
	<ol>
<?PHP
	
for($i=1;$i<=4;++$i)
{
	if( isset($_POST['p'.$i]))
	{
		$settings->highlight_link[$i-1]=$_POST['p'.$i];
		$settings->highlight_image[$i-1]=$_POST['p'.$i.'img'];
	}
}
file_put_contents($templatePath."/settings.txt", json_encode($settings));

/*********** processing begin here */
	
$files=array();
if ($handle = opendir($templatePath."/data.pics/content-slider/")) {
    while (false !== ($entry = readdir($handle))) {
        //echo "$entry\n";
		if( $entry!=='.' && $entry!=='..')
			array_push($files,$entry);
    }
    closedir($handle);
}
else
	die ("Could not open directory");

	//print_r($_POST);
/***** output html */
	for($i=1; $i<=4; ++$i)
	{
		echo "<li>";
		
		echo '<label for="p'. $i . '">Post '. $i .' link: </label>';
		echo "<input nobanglatext='true' size='50' ";
		echo 'name="p'. $i. '"';
		echo ' maxlength="100" size="20"';
		if( isset($_POST["p".$i]))
			echo ' value="'.$_POST["p".$i].'"';
		else	
			//echo ' value=""';
			echo ' value="'. $settings->highlight_link[$i-1] . '"';
		
		echo "/>";
		
		echo '<label for="p'. $i . 'img"> Image: </label>';
		echo '<select name="p'.$i.'img">';
			foreach($files as $val)
			{
				echo "<option value='".$val."'";
				
				if( $val == $settings->highlight_image[$i-1] )
					echo " selected='selected' ";
					
				echo ">".$val."</option>";
			}
		echo "</select>";
		
		echo "</li>";
	}
?>
<br/>
	<input type="submit" value="Submit these values" />
    </ul>
</form>